package com.zsrd.self.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zsrd.self.base.Result;
import com.zsrd.self.entity.OrderDiscounts;
import com.zsrd.self.entity.SelfUser;
import com.zsrd.self.entity.SelfWxConfig;
import com.zsrd.self.mapper.SelfWxConfigMapper;
import com.zsrd.self.service.OrderDiscountsService;
import com.zsrd.self.service.SelfUserService;
import com.zsrd.self.service.SelfWxConfigService;
import org.hibernate.validator.constraints.pl.REGON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/wx-pay")
public class OrderDiscountsController {

    @Autowired
    private OrderDiscountsService orderDiscountsService;

    @Autowired
    SelfWxConfigService selfWxConfigService;

    @PostMapping("/jump")
    public Result jump(@RequestBody OrderDiscounts orderDiscounts) {
        LambdaQueryWrapper<OrderDiscounts> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderDiscounts::getOpenId, orderDiscounts.getOpenId());
        OrderDiscounts o = orderDiscountsService.getOne(wrapper);
        String code = o.getCode();// 10 待支付 20 支付成功
        LambdaQueryWrapper<SelfWxConfig> wrapper1 = new LambdaQueryWrapper<>();
        wrapper1.eq(SelfWxConfig::getTagType, code);
        SelfWxConfig one = selfWxConfigService.getOne(wrapper1);
        String postUrl = one.getPostUrl();
        return Result.success(postUrl);
    }
}
